package com.yundows.safe;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteOpenHelper;

public class DbHelper extends SQLiteOpenHelper {
	private final static String dbname = "facesafe.db";
	private final static int version = 1;
	private static SQLiteDatabase db;
	private static DbHelper dbHelper;

	public static SQLiteDatabase get(Context context) {
		if (dbHelper == null) {
			dbHelper = new DbHelper(context, null);
		}
		if (db == null) {
			db = dbHelper.getWritableDatabase();
		}
		return db;
	}

	public DbHelper(Context context, CursorFactory factory) {
		super(context, dbname, factory, version);
	}

	public void onCreate(SQLiteDatabase db) {
		db.execSQL("CREATE TABLE IF NOT EXISTS `faces` ( `data` BLOB NOT NULL);");

		db.execSQL("CREATE TABLE IF NOT EXISTS `avg` ( `avg` BLOB NOT NULL);");

		db.execSQL("CREATE TABLE IF NOT EXISTS `eignvectors` ( `evector` BLOB NOT NULL);");

		db.execSQL("CREATE TABLE IF NOT EXISTS `eignfaces` (`isuser` BOOLEAN NOT NULL, `fvector` BLOB NOT NULL);");
	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		// TODO Auto-generated method stub

	}

}
